package com.uinnova.product.eam.service.impl;

import com.binary.core.util.BinaryUtils;
import com.uinnova.product.eam.comm.model.OceanDiagram;
import com.uinnova.product.eam.db.OceanDiagramDao;
import com.uinnova.product.eam.service.OceanDiagramService;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

@Service
@Log4j2
public class OceanDiagramSvcImpl implements OceanDiagramService {

    @Resource
    private OceanDiagramDao oceanDiagramDao;

    @Override
    public OceanDiagram selectLastOne() {
        return oceanDiagramDao.selectLastOne();
    }

    @Override
    public void deleteAll() {
        oceanDiagramDao.deleteAll();
    }

    @Override
    public void deleteByDiagramIds(Set<String> deleteDiagramIds) {
        oceanDiagramDao.deleteByDiagramIds(deleteDiagramIds);
    }

    @Override
    public void saveBatch(List<OceanDiagram> oceanDiagrams) {
        oceanDiagramDao.saveBatch(oceanDiagrams);
    }

    @Transactional
    @Override
    public void syncData(List<OceanDiagram> oceanDiagrams, boolean isFirst, Set<String> deleteDiagramIds) {
        if (!isFirst && !BinaryUtils.isEmpty(deleteDiagramIds)) {
            // 先删后增
            oceanDiagramDao.deleteByDiagramIds(deleteDiagramIds);
        }
        oceanDiagramDao.saveBatch(oceanDiagrams);
    }

    @Override
    public void deleteAndSave(List<OceanDiagram> oceanDiagrams) {
        oceanDiagramDao.deleteAll();
        oceanDiagramDao.saveBatch(oceanDiagrams);
    }
}
